package com.example.goodpet.activity.adapter;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.goodpet.R;

import java.util.List;

public class UploadImageAdapter extends RecyclerView.Adapter<UploadImageAdapter.ViewHolder> {

    private List<Bitmap> list;

//    private static final int ITEM_ONE=1;
//    private static final int ITEM_TWO=2;

    public UploadImageAdapter(List<Bitmap> list){
        this.list=list;
    }

    @NonNull
    @Override
    public UploadImageAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image_albumupload, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull UploadImageAdapter.ViewHolder holder, int position) {

        holder.image.setImageBitmap(list.get(position));
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int changedPosition=holder.getAbsoluteAdapterPosition();
                list.remove(changedPosition);
                notifyItemRemoved(changedPosition);
            }
        });
    }
//    @Override
//    public int getItemViewType(int position) {
//        if(position>list.size()-1){
//            return ITEM_TWO;
//        }else {
//            return ITEM_ONE;
//        }
//    }
    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView image;
        private ImageView delete;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            image=itemView.findViewById(R.id.image);
            delete=itemView.findViewById(R.id.deleteImage);
        }
    }

/*    public class AnoViewHolder extends RecyclerView.ViewHolder {
        private ImageView image;
        public AnoViewHolder(@NonNull View View) {
            super(View);
            image=itemView.findViewById(R.id.addImage);
        }
    }*/
}
